<?php
namespace app\zhonghang\controller;
use think\Controller;
use think\Request;
use think\Db;
use think\Session;
use think\Cache;
require_once (APP_PATH . 'api/RewardApi.php');
class Type extends Controller {
 	public function _initialize(){
 		parent::_initialize();
 	}
	//空操作
	public function _empty(){
		header("HTTP/1.0 404 Not Found");
		$this->display('Public:404');
	}

	//首页一级分类
    public function type(){
 	    $list=DB::name('Goods_category')->where('parent_id','0')->select();
        if($list){
            $data['info']='首页一级分类';
            $data['status']='1';
            $data['data']=$list;
            return json($data);
        }else{
            $data['info']='暂无数据';
            $data['status']='-1';
            $data['data']=array();
            return json($data);
        }
    }

    public function remen(){
 	    $list=DB::name('Goods_category')->where('is_hot','1')->select();
 	    if($list){
            foreach($list as $k=>$v){
                $list[$k]['sanji']=DB::name('Goods_category')->where('parent_id',$list[$k]['id'])->select();
            }
            $data['info']='热门推荐下分类';
            $data['status']='1';
            $data['data']=$list;
            return json($data);
        }else{
            $data['info']='暂无数据';
            $data['status']='-1';
            $data['data']=array();
            return json($data);
        }
    }

    public function xiajiType(){
        $where['parent_id']=input('id');
        $xiaji=DB::name('goods_category')->where($where)->select();
        foreach($xiaji as $k=>$v){
            $xiaji[$k]['sanji']=DB::name('goods_category')->where('parent_id',$xiaji[$k]['id'])->select();
        }
        if($xiaji){
            $data['info']='点击的一级分类下的所有二级三级分类';
            $data['status']='1';
            $data['data']=$xiaji;
            return json($data);
        }else{
            $data['info']='暂无数据';
            $data['status']='-1';
            $data['data']=array();
            return json($data);
        }
    }


	
}